

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_app/controller/OrderControl.dart';
import 'package:flutter_app/widget/car_type_item.dart';
import 'package:get/get.dart';
class OrderPage extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new OrderPageState();
  }

}

class OrderPageState extends State<OrderPage>{

  final OrderController control = Get.put(OrderController());

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    control.getOrderDatas(context);
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Container(
      color: Color(0xfff4f4f4),
      child: Stack(
        children: [
          Container(
            color: Color(0xff1A4677),
            height: 400,
          ),
          Align(
            alignment: Alignment.topCenter,
            child: Container(
              width: 900,
              margin: EdgeInsets.only(top: 20),
              color:Colors.white ,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.start,
                children: [
                  choseCartype()
                ],
              ),
            ),
          )
        ],
      ),
    );
  }



  ///选择车型
  Widget choseCartype(){
    return Column(
      mainAxisAlignment: MainAxisAlignment.start,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Container(
          margin: EdgeInsets.only(left: 20,top: 20),
          child: Text("选择车型",style: TextStyle(color: Colors.black,fontSize: 20),),),
        Obx(()=>
        (control.baseInfo.value.carType!=null&&control.baseInfo.value.carType.length>0)?
          Container(
            height:130*(control.baseInfo.value.carType.length/6+(control.baseInfo.value.carType.length%6>0?1:0)),
            child:  GridView.builder(
              gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                crossAxisCount: 6,
              ),
              itemBuilder: (context, index) {
                return GestureDetector(
                  onTap: (){
                    control.baseInfo.update((data) {
                      for(int i=0;i<data.carType.length;i++){
                        data.carType[i].isSelect=false;
                      }
                      data.carType[index].isSelect=true;
                    });
                    control.carType.value=control.baseInfo.value.carType[index];
                  },
                  child: CarTypeItemPage(index),
                );
              },
              itemCount: control.baseInfo.value.carType.length,),
          )
            :SizedBox(height: 10,)),
            Obx(()=>CheckboxListTile(
                controlAffinity: ListTileControlAffinity.leading,
                value: control.isSelectWeiban.value,
                title: Text("带尾板)",style: TextStyle(color: Colors.black)),
                onChanged: (value){
                  control.isSelectWeiban.value=value;
                }))
      ],
    );
  }

}